<?php
namespace App\Http\Controllers\Home;

use App\DBs\Home\TrendDB;
use Illuminate\Http\Request;

class TrendController extends BaseController
{
    //大会动态

    public function __construct()
    {
        $this->dbTrend = new TrendDB();
    }

    //大会动态
    public function getTrendIndex()
    {
        $items = ['tongzhi'=>[],'jujiao'=>[],'jiabin'=>[]];
        //大会通知
        $tz = $this->dbTrend->getTzIndex();
        if ($tz['code']==0) $items['tongzhi'] = $tz['data'];
        //聚焦大会
        $jj = $this->dbTrend->getFocusIndex();
        if ($jj['code']==0) $items['jujiao'] = $jj['data'];
        //演讲嘉宾
        $jb = $this->dbTrend->getSpeakerIndex();
        if ($jb['code']==0) $items['jiabin'] = $jb['data'];
        return $this->toJson(0,'success',$items);
    }

    //大会相关
    public function getDhIndex()
    {
        $zl = $this->dbTrend->getZiliao();
        $items = [
            'way'=>$this->getDhWay(),
            'signup'=>$this->getSignup(),
            'award'=>$this->getAward(),
            'lunli'=>$this->getLunli(),
            'ziliao'=>$zl['code']==0 ? $zl['data'] : [],
        ];
        return $this->toJson(0,'success',$items);
    }

    //章程
    public function getDhWay()
    {
        $res = file_get_contents('dhway.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        $res['detail'] = json_decode($res['detail'],true);
        return $res;
    }

    //报名
    public function getSignup()
    {
        $res = file_get_contents('dhsignup.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        $res['detail'] = json_decode($res['detail'],true);
        return $res;
    }

    //奖项
    public function getAward()
    {
        $res = file_get_contents('dhaward.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        $res['detail'] = json_decode($res['detail'],true);
        return $res;
    }

    //伦理
    public function getLunli()
    {
        $res = file_get_contents('dhlunli.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        $res['detail'] = json_decode($res['detail'],true);
        return $res;
    }

    //学术委员会
    public function getLearnIndex()
    {
        $res = $this->dbTrend->getLearnIndex();
        if ($res['code']!=0) {
            return $this->toJson(-2,$res['msg']);
        }
        return $this->toJson(0,'success',$res['data']);
    }

    //关于我们
    public function getAboutIndex()
    {
        $items = ['zzjg'=>'','yxg'=>[],'contact'=>[]];
        //组织架构
        $items['zzjg'] = $this->getZzjg();
        //影像馆
        $yxg = $this->dbTrend->getYxgIndex();
        if ($yxg['code']==0) $items['yxg'] = $yxg['data'];
        //联系方式、地图
        $items['contact'] = $this->getLxfs();
        return $this->toJson(0,'success',$items);
    }

    //组织机构
    public function getZzjg()
    {
        $res = file_get_contents('dhzzjg.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        return $res;
    }

    //联系方式
    public function getLxfs()
    {
        $res = file_get_contents('dhlianxi.json');
        if (!$res) return [];
        $res = json_decode($res,true);
        return $res;
    }
}